<template>
    <view>
        <view v-if="type !== 'pet'">
            <view v-if="List.hasImg === 1">
                <view class="margin-xl bg-white padding-xl radius shadow-lg">
                    <view class="text-center margin-bottom text-lg text-grey">图片信息</view>
                    <swiper
                        :class="'screen-swiper ' + (DotStyle ? 'square-dot' : 'round-dot')"
                        :indicator-dots="true"
                        :circular="true"
                        :autoplay="true"
                        interval="5000"
                        duration="500">
                        <swiper-item v-for="(item, index) in List.img" :key="index">
                            <image :src="item.ImgUrl" mode="aspectFill"></image>
                        </swiper-item>
                    </swiper>
                </view>
            </view>
            <view class="margin-xl bg-white padding-xl radius shadow-lg">
                <view class="text-center margin-bottom text-lg text-grey">{{ List.title }}</view>
                <view class="text-content">
                    <view>简介:{{ List.content === '' ? '他没有编辑详情内容哦' : List.content }}</view>
                    <view class="margin-top-sm" v-if="List.hasReward === 1 && List.thing === 1">他索求的报酬为：{{ List.reward }}</view>
                    <view class="margin-top-sm" v-if="List.hasReward === 1 && List.master === 1">归还失物的奖励：{{ List.reward }}</view>
                    <view class="margin-top-sm text-right">发布时间：{{ List.time }}</view>
                </view>
            </view>
            <button class="cu-btn block bg-blue margin-xl lg" @tap="Show" :disabled="List.complete=='1'" data-type="thing" v-if="List.thing === 1 && userInfo.Id !== List.uid">这是我的东西！</button>
            <button class="cu-btn block bg-blue margin-xl lg" @tap="Confirm" :disabled="List.complete=='1' || clicked===1" v-if="userInfo.Id === List.uid">已被找回</button>
            <button class="cu-btn block bg-blue margin-xl lg" @tap="Show" :disabled="List.complete=='1'" data-type="master" v-if="List.master === 1 && userInfo.Id !== List.uid">这应该就是失主！</button>
            <view :class="'cu-modal ' + (show === 1 ? 'show' : '')">
                <view class="cu-dialog">
                    <view class="cu-bar bg-white justify-end">
                        <view class="content">联系方式</view>
                        <view class="action" @tap="Hide">
                            <text class="cuIcon-close text-red"></text>
                        </view>
                    </view>
                    <view class="padding-xl">
                        <view>QQ:{{ List.qq }}</view>
                        <view>手机号：{{ List.phone }}</view>
                    </view>
                    <view class="cu-bar bg-white">
                        <view class="action margin-0 flex-sub text-red" @tap="Copy">复制</view>
                        <view class="action margin-0 flex-sub text-green solid-left" @tap="Hide">取消</view>
                        <view class="action margin-0 flex-sub solid-left" @tap="Hide">确定</view>
                    </view>
                </view>
            </view>
        </view>
    </view>
</template>


<script>
// pages/detail/detail.js
const app = getApp();

const getData = (url, param) => {
    return new Promise((resolve, reject) => {
        uni.request({
            url: url,
            method: 'POST',
            data: param,
            header: {
                'Content-Type': 'application/json'
            },

            success(res) {
                resolve(res.data);
            },

            fail(err) {
                reject(err);
            }
        });
    });
};

export default {
    data() {
        return {
            id: '',
            type: '',
			clicked:0,
            List: {
                hasImg: 0,
                img: [],
                title: '',
                content: '',
                hasReward: 0,
                thing: 0,
                reward: '',
                master: 0,
                time: '',
                uid: '',
                qq: '',
                phone: '',
                name: '',
                varieties: '',
                age: '',
                description: '',
				complete:'0'
            },

            userInfo: {
                Id: ''
            },

            show: 0,
            DotStyle: false
        };
    }
    /**
     * 生命周期函数--监听页面加载
     */,
    onLoad: function (options) {
        uni.showLoading({
            title: '加载中...'
        });
        var that = this;
        this.setData({
            type: options.type,
            id: options.id
        });
        getData(app.globalData.ApiUrl + 'api/Android/Detail', {
            type: options.type,
            id: options.id
        }).then((msg) => {
			
			console.log("失物寻找数据");
			console.log(msg);
			
            that.setData({
                List: msg
            });
        });
        uni.request({
            url: app.globalData.ApiUrl + 'api/Android/UserInfo',
        
            //这里填写你的接口路径
            header: {
                'Content-Type': 'application/json'
            },
        
            data: {
                //这里写你要请求的参数
                SafeCode: uni.getStorageSync('SafeCode')
            },
        
            success: function (res) {
                that.setData({
                    userInfo: res.data
                });
                uni.hideLoading();
            }
        });
    },
    methods: {
        
        Show: function (e) {
            var that = this; //管他三七二十一，反正通知主人就对了

            getData(app.globalData.ApiUrl + 'api/Android/Contact', {
                List: that.List,
                UserInfo: that.userInfo
            });
            this.setData({
                show: 1
            });
        },

        Hide: function (e) {
            this.setData({
                show: 0
            });
        },

        Copy: function (e) {
            var that = this;
            uni.setClipboardData({
                data: 'QQ:' + that.List.qq + '\n手机:' + that.List.phone,
                success: (res) => {
                    uni.showToast({
                        title: '已复制',
                        duration: 1000
                    });
                }
            });
        },

        Confirm: function () {
			this.setData({
				clicked:1
			});
            var that = this;
            var id = this.id;
            var type = this.type;
            var SafeCode = uni.getStorageSync('SafeCode');
            getData(app.globalData.ApiUrl + 'api/Android/Confirm', {
                id: id,
                type: type,
                SafeCode: SafeCode
            }).then((msg) => {
                if (msg.result === 'success') {
                    uni.showToast({
                        title: '操作完成',
                        icon: 'success',
                        duration: 1500
                    });
                } else {
                    uni.showToast({
                        title: msg.msg,
                        icon: 'error',
                        duration: 1500
                    });
                }
            });
        }
    }
};
</script>
<style>
@import './detail.css';
</style>
